package logic

import (
	"context"
	"log"
	"month/videosvr/video"

	"month/client/internal/svc"
	"month/client/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadVideoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadVideoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadVideoLogic {
	return &UploadVideoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UploadVideoLogic) UploadVideo(req *types.UploadVideoReq) (resp *types.Res, err error) {
	// todo: add your logic here and delete this line
	log.Println(req.Video, req.Img, req.Index, req.Userid, req.Typeid, "//////")
	_, err = l.svcCtx.VideoRpc.UploadVideo(l.ctx, &video.CreateVideoReq{
		Index:    req.Index,
		Title:    req.Title,
		SubTitle: req.SubTitle,
		TypeId:   int64(req.Typeid),
		Address:  req.Address,
		Video:    req.Video,
		Img:      req.Img,
		Userid:   int64(req.Userid),
	})
	if err != nil {
		return &types.Res{
			Code: -1,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Res{
		Code: 200,
		Msg:  "success",
		Data: map[string]interface{}{
			"videoUrl": req.Video,
			"imgUrl":   req.Img,
		},
	}, nil
}
